home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / camera / camcompat.c next >
Encoding:
C/C++ Source or Header  |  1992-08-31  |  4.4 KB  |  209 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include <math.h>
  13. #include <stdio.h>
  14. #include "ooglutil.h"
  15. #include "handle.h"
  16. #include "streampool.h"
  17. #include "cameraP.h"
  18. #include "transobj.h"
  19.  
  20. extern HandleOps CamOps;
  21.  
  22. Camera *
  23. CamFLoad(Camera *proto, FILE *inf, char *fname)
  24. {
  25.     Pool *p;
  26.     Camera *cam = NULL;
  27.  
  28.     p = PoolStreamTemp(fname, inf, 0, &CamOps);
  29.     if(p == NULL)
  30.     return NULL;
  31.     if(proto != NULL)
  32.     OOGLError(1, "Note: CamFLoad(cam, ...) can't handle cam != NULL");
  33.     (void) CamStreamIn(p, NULL, &cam);
  34.     PoolDelete(p);
  35.     return cam;
  36. }
  37.  
  38. void
  39. CamFSave(Camera *cam, FILE *outf, char *fname)
  40. {
  41.     Pool *p = PoolStreamTemp(fname, outf, 1, &CamOps);
  42.     if(p == NULL)
  43.     return;
  44.     (void) CamStreamOut(p, NULL, cam);
  45.     PoolDelete(p);
  46. }
  47.  
  48. Camera *
  49. CamLoad(Camera *cam, char *name)
  50. {
  51.   FILE *f;
  52.   
  53.   if((f = fopen(name,"r")) == NULL) {
  54.     perror(name);
  55.     return NULL;
  56.   }
  57.   cam = CamFLoad(cam, f, name);
  58.   fclose(f);
  59.   return cam;
  60. }
  61.  
  62.  
  63. void
  64. CamSave(Camera *cam, char *name)
  65. {
  66.     FILE *f;
  67.  
  68.     if((f = fopen(name, "w")) == NULL) {
  69.     perror(name);
  70.     return;
  71.     }
  72.     CamFSave(cam, f, name);
  73.     fclose(f);
  74. }
  75.  
  76.  
  77. /* I'm not sure what to do with the following procedure.  On one hand
  78.    I think it should come out and be replaced by get-only attributes??
  79.    On the other hand, it's nice to be able to get both eyes in one call.
  80.    I need to understand more about how stereo works.  Until then, I'm
  81.    commenting this procedure out.  -- mbp Fri Aug  9 00:32:36 1991 */
  82. #ifdef notdef
  83. int
  84. CamCurrentStereo( register Camera *cam, Transform leye, Transform reye )
  85. {
  86.     if(leye != TMNULL) TmCopy(cam->stereyes[0], leye);
  87.     if(reye != TMNULL) TmCopy(cam->stereyes[1], reye);
  88.     return cam->whicheye;
  89. }
  90. #endif
  91.  
  92. /************************************************************************
  93.  * The following procedures are on death row; they will be taken out    *
  94.  * soon because they have been superceded by CamGet and CamSet          *
  95.  ************************************************************************/
  96.  
  97. void
  98. CamCurrentPosition( register Camera *cam, Transform T )
  99. {
  100.     TmCopy( cam->camtoworld, T );
  101. }
  102.  
  103. /*
  104.  * Return world -> camera coordinate transform in T.
  105.  * Note this is the inverse of the transform given by CamCurrentPosition().
  106.  */
  107. void
  108. CamViewWorld( register Camera *cam, Transform T )
  109. {
  110.     if (cam->flag & CAMF_NEWC2W ) {
  111.     TmInvert( cam->camtoworld, cam->worldtocam );
  112.     cam->flag &= ~CAMF_NEWC2W;
  113.     }
  114.     /* else we have the actual worldtocam transform already computed */
  115.     TmCopy( cam->worldtocam, T );
  116. }
  117.  
  118.  
  119. void
  120. CamFocus( register Camera *cam, float focus )
  121. {
  122.     cam->focus = focus;
  123. }
  124.  
  125. float
  126. CamCurrentFocus( register Camera *cam )
  127. {
  128.     return cam->focus;
  129. }
  130.  
  131. float
  132. CamCurrentAspect( register Camera *cam )
  133. {
  134.     return cam->frameaspect;
  135. }
  136.  
  137. /*
  138.  * Set aspect ratio; preserve minimum field-of-view.
  139.  */
  140. void
  141. CamFrameAspect( register Camera *cam, float aspect )
  142. {
  143.     cam->frameaspect = aspect;
  144. }
  145.  
  146. void
  147. CamTransformTo( register Camera *cam, Transform T )
  148. {
  149.     TmCopy( T, cam->camtoworld );
  150.     cam->flag |= CAMF_NEWC2W;
  151. }
  152.  
  153. /*
  154.  * Select which eye to view through in stereo mode.
  155.  */
  156. /* incorporate into CamSet & remove: */
  157. void
  158. CamStereoEye( register Camera *cam, int whicheye )
  159. {
  160.     if(whicheye > 1) whicheye = 1;
  161.     cam->whicheye = whicheye;
  162. }
  163.  
  164. void
  165. CamClipping( register Camera *cam, float near, float far )
  166. {
  167.     cam->near = near;
  168.     cam->far = far;
  169. }
  170.  
  171. void
  172. CamCurrentClipping( register Camera *cam, float *near, float *far )
  173. {
  174.     *near = cam->near;
  175.     *far = cam->far;
  176. }
  177.  
  178. void
  179. CamHalfYField( register Camera *cam, float halfyfov )
  180. {
  181.     cam->halfyfield = halfyfov;
  182. }
  183.  
  184. float
  185. CamCurrentHalfYField( register Camera *cam )
  186. {
  187.     return cam->halfyfield;
  188. }
  189.  
  190. float
  191. CamCurrentHalfField( register Camera *cam )
  192. {
  193.     return cam->frameaspect > 1 ?
  194.         cam->halfyfield : cam->halfyfield * cam->frameaspect;
  195. }
  196.  
  197. void
  198. CamPerspective( register Camera *cam, int persp )
  199. {
  200.     if (persp)  cam->flag |= CAMF_PERSP;
  201.     else    cam->flag &= ~CAMF_PERSP;
  202. }
  203.  
  204. int
  205. CamIsPerspective( register Camera *cam )
  206. {
  207.     return ((cam->flag & CAMF_PERSP) != 0);
  208. }
  209.